package com.kanshu.basictest.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import androidx.annotation.Nullable;

import com.kanshu.basictest.IBinderPool;
import com.kanshu.basictest.service.binder.ComputeImpl;
import com.kanshu.basictest.service.binder.SecurityCenterImpl;

import static com.kanshu.basictest.service.binder.BinderPoolConstants.BINDER_COMPUTE;
import static com.kanshu.basictest.service.binder.BinderPoolConstants.BINDER_SECURITY_CENTER;

public class BinderPoolService extends Service {

    private Binder mBinderPool = new IBinderPool.Stub() {
        @Override
        public IBinder queryBinder(int binderCode) throws RemoteException {
            IBinder binder = null;
            switch (binderCode) {
                case BINDER_COMPUTE:
                    binder = new ComputeImpl();
                    break;
                case BINDER_SECURITY_CENTER:
                    binder = new SecurityCenterImpl();
                    break;
                default:
                    break;

            }
            return binder;
        }
    };

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return mBinderPool;
    }
}